<template>
	<view style="height: 100%;width: 100%;">
		<view class="QS-tabs-box">
			<QSTabs ref="tabs" :tabs="tabs" animationMode="line3" :current="current" @change="change" :swiperWidth="750">
			</QSTabs>
		</view>
		<!-- <swiper style="width100%;height: 100%;padding-bottom: 50px;background: #000;padding-top: 40px;" :current="current" @change="swiperChange" @transition="transition"
		 @animationfinish="animationfinish"> -->
			<!-- <swiper-item class="swiper-item" style="height: 100%;width: 100%;"> -->
				<scroll-view scroll-y style="height: 100%;width: 100%;padding-top: 40px;padding-bottom: 40px;" v-if="current==0">
					<view class="scroll-items">
						<radio-group class="block" @change="StockChange">
							<view class="cu-list menu text-left">
								<view class="cu-item" v-for="($item,$index) in PDA_Module_Android" :key="$index" @tap="mzsbq1($index)">
									<label class="flex justify-between align-center flex-sub">
										<view class="title1" style="flex-direction:column">{{$item.ModuleName}}</view>
										<!-- 	<jiuaiCheckbox @change='changeBox' :value="$item.IsCheck=='√'" :checked="$item.IsCheck=='√'" v-show="$item.type"></jiuaiCheckbox> -->
									</label>
								</view>
							</view>
						</radio-group>
					</view>
				</scroll-view>
			<!-- </swiper-item> -->
			<!-- <swiper-item class="swiper-item" style="height: 100%;width: 100%;"> -->
				<scroll-view scroll-y style="height: 100%;width: 100%;padding-top: 40px;padding-bottom: 40px;" v-if="current==1">
					<view class="scroll-items">
						<radio-group class="block" @change="StockChange">
							<view class="cu-list menu text-left">
								<view class="cu-item" v-for="($item,$index) in PDA_Module_Options" :key="$index">
									<label class="flex justify-between align-center flex-sub">
										<view class="title1" style="flex-direction:column">{{$item.ModuleName}}</view>
										<jiuaiCheckbox @change='OptionsChangeBox' :value="$item.IsBill=='√'" :checked="$item.IsBill=='√'" :index="$index"></jiuaiCheckbox>
									</label>
								</view>
							</view>
						</radio-group>
					</view>
				</scroll-view>
			<!-- </swiper-item> -->
			<!-- <swiper-item class="swiper-item" style="height: 100%;width: 100%;"> -->
				<scroll-view scroll-y style="height: 100%;width: 100%;padding-top: 40px;padding-bottom: 40px;" v-if="current==2">
					<view class="scroll-items">
						<radio-group class="block" @change="StockChange">
							<view class="cu-list menu text-left">
								<view style="font-size: 27rpx;color: #FFFFFF;font-weight: bold;background: rgb(124,170,216);padding: 10rpx;">开单取价权限</view>
								<view class="cu-item" v-for="($item,$index) in PDA_Price_Module" :key="$item.PriceType">
									<label class="flex justify-between align-center flex-sub">
										<view class="title1" style="flex-direction:column">{{$item.PriceType}}</view>
										<jiuaiCheckbox @change='PriceChangeBox' :value="$item.IsShow=='√'" :checked="$item.IsShow=='√'" :index="$index"></jiuaiCheckbox>
									</label>
								</view>
								<view style="font-size: 27rpx;color: #FFFFFF;font-weight: bold;background: rgb(124,170,216);padding: 10rpx;">商品信息显示权限</view>
								<view class="cu-item" v-for="($item,$index) in PDA_Price_Module2" :key="$index">
									<label class="flex justify-between align-center flex-sub">
										<view class="title1" style="flex-direction:column">{{$item.PriceType}}</view>
										<jiuaiCheckbox @change='PriceChangeBox1' :value="$item.IsShow=='√'" :checked="$item.IsShow=='√'" :index="$index"></jiuaiCheckbox>
									</label>
								</view>
							</view>
						</radio-group>
					</view>
				</scroll-view>
			<!-- </swiper-item> -->
			<!-- <swiper-item class="swiper-item" style="height: 100%;width: 100%;"> -->
				<scroll-view scroll-y style="height: 100%;width: 100%;padding-top: 40px;padding-bottom: 40px;" v-if="current==3">
					<view class="scroll-items">
						<radio-group class="block" @change="StockChange">
							<view class="cu-list menu text-left">
								<view class="cu-item" v-for="($item,$index) in PDA_Store_Module" :key="$index">
									<label class="flex justify-between align-center flex-sub">
										<view class="title1" style="flex-direction:column">{{$item.StoreType}}</view>
										<jiuaiCheckbox @change='StorehCangeBox' :value="$item.IsShow=='√'" :checked="$item.IsShow=='√'" :index="$index"></jiuaiCheckbox>
									</label>
								</view>
							</view>
						</radio-group>
					</view>
				</scroll-view>
			<!-- </swiper-item> -->
		<!-- </swiper> -->
		<view class="goodsCount">
			<view :data-item="current" @tap="save">保存</view>
		</view>
	</view>
</template>

<script>
	import QSTabs from '../../components/QS-tabs/QS-tabs.vue';
	import jiuaiCheckbox from "@/components/jiuai-checkbox.vue";
	import * as sypower from '@/syApis/sypower/sypower.js';
	import * as Api from '@/syApis/sySet/sySet.js'
	const Sys = uni.getSystemInfoSync();
	const wH = Sys.windowHeight;
	export default {
		components: {
			QSTabs,
			jiuaiCheckbox
		},
		data() {
			return {
				tabs: ['单据权限', '功能权限', '单价权限', '仓库权限'],
				current: 0,
				tabsHeight: 0,
				dx: 0,
				radio: '',
				UserID: 0,
				PDA_Module_Android: [],
				PDA_Module_Options: [],
				PDA_Price_Module: [],
				PDA_Price_Module2: [],
				PDA_Store_Module: []
			}
		},
		created() {
			// this.getSystemSettingInfo();

		},
		onLoad(options) {
			this.UserID = options.UserID;
		},
		onShow() {
			this.getGain_AllUsersRoot();
		},
		methods: {
			//功能权限
			OptionsChangeBox(e) {
				console.log(e);
				let value = e.detail.value;
				if (value) {
					this.PDA_Module_Options[e.detail.index].IsBill = "";
				} else {
					this.PDA_Module_Options[e.detail.index].IsBill = "√";
				}

			},
			//开单单价权限
			PriceChangeBox(e) {
				let value = e.detail.value;
				if (value) {
					this.PDA_Price_Module[e.detail.index].IsShow = "";
				} else {
					this.PDA_Price_Module[e.detail.index].IsShow = "√";
				}
			},
			//商品查询单价权限
			PriceChangeBox1(e) {
				let value = e.detail.value;
				if (value) {
					this.PDA_Price_Module2[e.detail.index].IsShow = "";
				} else {
					this.PDA_Price_Module2[e.detail.index].IsShow = "√";
				}
			},
			//商品查询单价权限
			StorehCangeBox(e) {
				let value = e.detail.value;
				if (value) {
					this.PDA_Store_Module[e.detail.index].IsShow = "";
				} else {
					this.PDA_Store_Module[e.detail.index].IsShow = "√";
				}
			},
			save(e) {
				// console.log(e.currentTarget.dataset.item);
				let index = e.currentTarget.dataset.item;
				if (index == 0) {
					console.log("单据权限")
				} else if (index == 1) {
					console.log("功能权限")
					// console.log(this.PDA_Module_Options);
					uni.showLoading({
						title: "加载中...",
					mask:false
					})
					this.Save_ModuleRoot();
				} else if (index == 2) {
					console.log("单价权限")
					uni.showLoading({
						title: "保存中...",
					mask:false
					})
					//保存单保存开单单价权限
					this.Save_BillPriceRoot();
				} else {
					uni.showLoading({
						title: "保存中...",
					mask:false
					})
					this.Save_StoreRoot();
					console.log("仓库权限")
				}

			},
			//保存功能权限
			Save_ModuleRoot() {
				let Save_D_Data_Json = [];
				for (let i in this.PDA_Module_Options) {
					var item = {
						"ModuleName": this.PDA_Module_Options[i].ModuleName,
						"IsBill": this.PDA_Module_Options[i].IsBill
					};
					Save_D_Data_Json.push(item);
				}
				let data = {
					Save_D_Data_Json: JSON.stringify(Save_D_Data_Json),
					UserID: this.UserID
				}
				Api.Save_ModuleRoot(data, function(res) {
					if (res.state) {
						if (res.data.ErrorMsg == '获取登录信息失败') {

						} else if (res.data.ErrorMsg != '') {
							Api.showTip(res.ErrorMsg);
						} else {
							Api.showTip("保存成功");
						}
					}
				});
				uni.setStorageSync("PDA_Module_Options", JSON.stringify(this.PDA_Module_Options)); //存储功能权限
			},
			//保存商品开单权限
			Save_GoodSelect_PriceRoot() {
				let Save_D_Data_Json = [];
				//保存商品查询单价权限接口
				for (let var2 in this.PDA_Price_Module2) {
					var item = {
						"PriceType": this.PDA_Price_Module2[var2].PriceType,
						"IsShow": this.PDA_Price_Module2[var2].IsShow
					}
					Save_D_Data_Json.push(item);
				}
				let data = {
					Save_D_Data_Json: JSON.stringify(Save_D_Data_Json),
					UserID: this.UserID
				}

				sypower.Save_GoodSelect_PriceRoot(data, function(res) {
					if (res.state) {
						if (res.data.ErrorMsg == '获取登录信息失败') {
							uni.hideLoading();
						} else if (res.data.ErrorMsg != '') {
							Api.showTip(res.ErrorMsg);
							uni.hideLoading();
						} else {
							Api.showTip("保存商品查询单价权限成功");

						}
					} else {
						uni.hideLoading();
					}
				});
				uni.setStorageSync("PDA_Price_Module2", JSON.stringify(this.PDA_Price_Module2)); //存储商品信息显示权限
			},
			//保存开单单价权限
			Save_BillPriceRoot() {
				let Save_D_Data_Json = [];
				for (let var1 in this.PDA_Price_Module) {
					var item = {
						"PriceType": this.PDA_Price_Module[var1].PriceType,
						"IsShow": this.PDA_Price_Module[var1].IsShow
					}
					Save_D_Data_Json.push(item);
				}
				var that = this;
				let data = {
					Save_D_Data_Json: JSON.stringify(Save_D_Data_Json),
					UserID: this.UserID
				}
				sypower.Save_BillPriceRoot(data, function(res) {
					uni.hideLoading();
					if (res.state) {
						if (res.data.ErrorMsg == '获取登录信息失败') {

						} else if (res.data.ErrorMsg != '') {
							Api.showTip(res.ErrorMsg);
						} else {
							Api.showTip("保存单保存开单单价权限成功");
							that.Save_GoodSelect_PriceRoot();
						}
					}
				});
				uni.setStorageSync("PDA_Price_Module", JSON.stringify(this.PDA_Price_Module)); //存储单价权限
			},
			//保存仓库权限
			Save_StoreRoot() {
				let Save_D_Data_Json = [];
				//保存仓库权限权限接口
				for (let index in this.PDA_Store_Module) {
					var item = {
						"StoreType": this.PDA_Store_Module[index].StoreType,
						"IsShow": this.PDA_Store_Module[index].IsShow
					}
					Save_D_Data_Json.push(item);
				}
				let data = {
					Save_D_Data_Json: JSON.stringify(Save_D_Data_Json),
					UserID: this.UserID
				}
				sypower.Save_StoreRoot(data, function(res) {
					uni.hideLoading();
					if (res.state) {
						if (res.data.ErrorMsg == '获取登录信息失败') {

						} else if (res.data.ErrorMsg != '') {
							Api.showTip(res.ErrorMsg);
						} else {
							Api.showTip("保存仓库权限成功");
						}
					}
				});
				uni.setStorageSync("PDA_Store_Module", JSON.stringify(that.PDA_Store_Module)); //存储仓库权限
			},
			//单据条目点击事件
			mzsbq1(inIndex) {
				let PDA_ModuleItem = this.PDA_Module_Android[inIndex];
				console.log(JSON.stringify(PDA_ModuleItem));
				uni.navigateTo({
					url: '../danju-setPower/danju-setPower?PDA_ModuleItem=' + JSON.stringify(PDA_ModuleItem) + "&UserID=" + this.UserID
				})
			},
			change(index) {
				this.current = index;
			},
			//获取登录权限设置的内容
			getGain_AllUsersRoot() {
				uni.showLoading({
					title: "加载中...",
					mask:false
				})
				this.PDA_Module_Android = [],
					this.PDA_Module_Options = [],
					this.PDA_Price_Module = [],
					this.PDA_Price_Module2 = [],
					this.PDA_Store_Module = []
				let data = {
					UserID: this.UserID
				};
				var that = this;
				sypower.Gain_AllUsersRoot(data, function(res) {
					uni.hideLoading();
					sypower.showTip("加载成功");
					if (res.state) {
						if (res.data.ErrorMsg == "No connection could be made because the target machine actively refused it") {

						} else if (res.data.ErrorMsg != "") {

						} else {
							// //console.tablele(res.data.ResultMsg)
							that.gbtzList = res.data.ResultMsg;
							console.log(res.data.ResultMsg);
							that.PDA_Price_Module = res.data.ResultMsg.PDA_Price_Module;
							that.PDA_Price_Module2 = res.data.ResultMsg.PDA_Price_Module2;
							that.PDA_Store_Module = res.data.ResultMsg.PDA_Store_Module;
							res.data.ResultMsg.PDA_Module_Android.forEach((item, index) => {
								if (item.UType == 1) {
									that.PDA_Module_Android.push(item);
								} else {
									that.PDA_Module_Options.push(item);
								}
							});
							uni.setStorageSync("PDA_Price_Module", JSON.stringify(that.PDA_Price_Module)); //存储单价权限
							uni.setStorageSync("PDA_Price_Module2", JSON.stringify(that.PDA_Price_Module2)); //存储商品信息显示权限
							uni.setStorageSync("PDA_Store_Module", JSON.stringify(that.PDA_Store_Module)); //存储仓库权限
							uni.setStorageSync("PDA_Module_Android", JSON.stringify(that.PDA_Module_Android)); //存储单据权限
							uni.setStorageSync("PDA_Module_Options", JSON.stringify(that.PDA_Module_Options)); //存储功能权限
						}
					} else {
						sypower.showTip("服务器超时")
					}
				})
			},
			swiperChange({
				detail: {
					current
				}
			}) {
				this.current = current;
			},
			transition({
				detail: {
					dx
				}
			}) {
				this.$refs.tabs.setDx(dx);
			},
			animationfinish({
				detail: {
					current
				}
			}) {
				this.$refs.tabs.setFinishCurrent(current);
			}
		}
	}
</script>

<style lang="scss" scoped>
	page {
		width: 100%;
		height: 100%;
		padding-bottom: 0 !important;
	}
	

	.QS-tabs-box {
		width: 100%;
		position: fixed;
		// top: 0;
		z-index: 10;
		background-color: white;
	}

	.swiper-item {
		/* background-color: #f1505c; */
	}

	.scroll-items {
		display: flex;
		flex-direction: column;
		width: 100%;
		padding-left: 40rpx;
		padding-right: 40rpx;
	}

	.scroll-item {
		margin-top: 15rpx;
		padding: 25rpx;
		background-color: white;
		border-radius: 8rpx;
		width: 100%;
		display: flex;
		flex-direction: row;
	}

	.scroll-item-image-box {
		flex-grow: 0;
	}

	.scroll-item-text-box {
		flex-grow: 1;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		font-size: 28rpx;
		font-weight: bold;
		margin-left: 15rpx;
	}

	.scroll-item-image {
		border-radius: 4rpx;
		width: 180rpx;
		height: 150rpx;
	}

	.cu-form-box {
		display: flex;
		align-items: center;
		width: 100%;
	}


	@import url("../../style/weui.css");

	page {
		padding-bottom: 120upx;
	}

	.content {
		position: relative;
	}

	.list {
		display: flex;
		align-items: center;
		padding: 20upx 30upx;
		;
		background: #fff;
		position: relative;
	}

	.wrapper {
		display: flex;
		flex-direction: column;
		flex: 1;
	}

	.address-box {
		display: flex;
		align-items: center;

		.tag {
			font-size: 24upx;
			color: rgba(34, 164, 255, 1.0);
			margin-right: 10upx;
			background: rgb(230, 246, 247);
			border: 1px solid rgba(34, 164, 255, 1.0);
			border-radius: 4upx;
			padding: 4upx 10upx;
			line-height: 1;
		}

		.address {
			font-size: 30upx;
			color: $font-color-dark;
		}
	}

	.u-box {
		font-size: 28upx;
		color: $font-color-light;
		margin-top: 16upx;

		.name {
			margin-right: 30upx;
		}
	}

	.icon-bianji {
		display: flex;
		align-items: center;
		height: 80upx;
		font-size: 40upx;
		color: $font-color-light;
		padding-left: 30upx;
	}

	.add-btn {
		position: fixed;
		left: 30upx;
		right: 30upx;
		bottom: 16upx;
		z-index: 95;
		display: flex;
		align-items: center;
		justify-content: center;
		width: 690upx;
		height: 80upx;
		font-size: 32upx;
		color: #fff;
		background-color: rgba(34, 164, 255, 1.0);
		border-radius: 10upx;
		box-shadow: 1px 2px 5px rgba(219, 63, 96, 0.4);
	}

	.goodsCount {
		width: 100%;
		height: 100upx;
		line-height: 100upx;
		position: fixed;
		bottom: 0px;
		left: 0px;
		background: rgb(124, 170, 216);
		text-align: center;
		z-index: 9999;
		display: flex;
		flex-direction: row;
		color: #FFFFFF;
	}

	.goodsCount view {
		text-align: center;
		flex: 1;
		box-sizing: border-box;
		border-right: 1upx solid #ccc;
	}

	.goodsCount view:last-child {
		border-right: none;
	}

	.goodsCount.goodCar {
		display: flex;
		flex-direction: row;
	}

	.goodsCount.goodCar .carIcon {
		width: 100upx;
		height: 100upx;
		text-align: center;
		position: relative;
	}

	.goodsCount.goodCar .carIcon image {
		width: 50upx;
		height: 50upx;
		margin-top: 25upx;
		margin-left: 25upx;
	}

	.goodsCount.goodCar .carIcon text {
		position: absolute;
		min-width: 25upx;
		height: 30upx;
		right: 10upx;
		top: 18upx;
		line-height: 30upx;
		background: red;
		border-radius: 25upx;
		padding-left: 8upx;
		padding-right: 8upx;
		color: #FFF;
		font-size: 20upx;
	}

	.goodsCount.goodCar .priceAll {
		flex: 4;
	}

	.goodsCount.goodCar .sureBt {
		flex: 2;
		background: #68e4e6;
		color: #FFF;
	}

	.goodsCount.goodCar .carInfo {
		position: fixed;
		bottom: 100upx;
		min-height: 100upx;
		background: #FFF;
		width: 100%;
	}

	.goodsCount.goodCar .carTitle {
		height: 60upx;
		line-height: 60upx;
		display: flex;
	}

	.goodsCount.goodCar .carTitle text {
		flex: 1;
		text-align: left;
		padding-left: 30upx;
		padding-right: 30upx;
		background: #68e4e6;
		color: #FFF;
	}

	.goodsCount.goodCar .carTitle text:last-child {
		text-align: right;
	}

	.goodsCount.goodCar .carList {
		max-height: 448upx;
		overflow: auto;
	}

	.goodsCount.goodCar .carList .carItem {
		width: 100%;
		display: flex;
		flex-direction: row;
		height: 100upx;
		line-height: 100upx;
		padding-top: 10upx;
		padding-bottom: 10upx;
	}

	.goodsCount.goodCar .carList .carItem image {
		width: 60upx;
		height: 60upx;
		margin-top: 20upx;
		margin-left: 10upx;
		margin-right: 30upx;
	}

	.goodsCount.goodCar .carList .carItem .goodInfo {
		flex: 2;
		display: flex;
		flex-direction: column;
	}

	.goodsCount.goodCar .carList .carItem .goodInfo text {
		flex: 1;
		line-height: 50upx;
		text-align: left;
	}

	.goodsCount.goodCar .carList .carItem .numOptions {
		flex: 1;
		box-sizing: border-box;
		padding-top: 20upx;
		padding-left: 30upx;
		padding-right: 30upx;
	}

	.goodsCount.goodCar .carList .carItem .numOptions .numOptionsWrap {
		width: 100%;
		height: 50upx;
		border: 1px solid #68e4e6;
		display: flex;
		border-radius: 10upx;
	}
</style>
